<?php

class ControllerModuleLastestnews extends Controller {

    protected function index($setting) {

        $this->load->model('catalog/news');

        $this->load->model('tool/image');

        // tin mới nhất
        $news = $this->model_catalog_news->tinmoinhat(2);
        if (count($news) > 0) {
            foreach ($news as $key => $result) {
                $first_img = '';
                $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), $matches);
                if ($matches [1]) {
                    $first_img = $matches [1] [0];
                } else {
                    $first_img = "image/no_image.jpg";
                }
                $this->data['newss'][] = array(
                    'item_id' => $result['news_id'],
                    'title' => $result['title'],
                    'date_added' => date('h:iA d/m/Y', strtotime($result['date_added'])),
                    'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 130, 'UTF-8').'...',
                    'image' => $first_img,
                    'href' => HTTP_SERVER . 'news/' . $result['news_category'] . '/' . $result['seo_name'] . '.html'
                );
            }
        }

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/lastestnews.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/lastestnews.tpl';
        } else {
            $this->template = 'default/template/module/lastestnews.tpl';
        }

        $this->render();
    }

}

?>